package com.area.cth.controller.admin;

import com.area.cth.common.PageBean;
import com.area.cth.common.Result;
import com.area.cth.pojo.Post;
import com.area.cth.service.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "管理端帖子相关接口")
@RestController("adminPostController")
@RequestMapping("/admin/post")
@CrossOrigin
@Slf4j
public class PostController {
    @Autowired
    private PostService ps;

    @Operation(summary = "根据id查询帖子")
    @GetMapping("/getById")
    public Result<Post> postById(Integer id) {
        Post postById = ps.getPostById(id);
        return Result.success(postById);
    }

    @Operation(summary = "分页查询")
    @GetMapping("/list")
    public Result<PageBean<Post>> getPostList(Integer pageNo, Integer pageSize) {
        PageBean<Post> postList = ps.postList(pageNo, pageSize);
        return Result.success(postList);
    }

    @Operation(summary = "删除帖子")
    @DeleteMapping
    public Result deletePost(Integer id) {
        ps.deletePost(id);
        return new Result(0,"删除成功",null);
    }
}
